#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void *Sleep_thread(void *args)
{
    printf("睡觉线程(%d)开始执行\n", gettid());
    sleep(5);
}

int main(int argc, char const *argv[])
{
    printf("main线程(%d)开始执行\n", gettid());

    pthread_t pt1 = 0;
    pthread_create(&pt1, NULL, Sleep_thread, NULL);
    sleep(1);

    void *result = NULL;
    pthread_cancel(pt1);
    pthread_join(pt1, &result);
    if(result == PTHREAD_CANCELED)
    {
        printf("睡觉线程被取消\n");
    }
    else
    {
        printf("睡觉线程执行完毕\n");
    }
    printf("main线程(%d)即将执行完毕\n", gettid());
    return 0;
}
